package demo01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;

public class zuoye08 {
	public static void main(String[] args) {
		ArrayList<String> poker = new ArrayList<>();
		String[] colors={"♠","♣","♥","♦"}; 
		String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
		poker.add("大王");poker.add("小王");
		for(String number : numbers){
			for(String color: colors){
				poker.add(color+number);
			}
		}
		LinkedHashMap<String,Integer> map=new LinkedHashMap();
		int value = 0;
		for(String s: poker){
			map.put(s, value);	
			value++;
		}
		Collections.shuffle(poker);
		System.out.println(map);
		Player player1=new Player("老王");
		Player player2=new Player("老李");
		Player player3=new Player("老刘");
		
		for(int i=0;i<poker.size();i++){
			String p = poker.get(i);
			if(i%3==0){
				player1.getList().add(p);
			}else if(i%3==1){
				player2.getList().add(p);
			}else if(i%3==2){
				player3.getList().add(p);
			}
		}
		ArrayList<Integer> num1 = new ArrayList<>();
		ArrayList<Integer> num2 = new ArrayList<>();
		ArrayList<Integer> num3 = new ArrayList<>();
		for(String s: player1.getList()){
			value = map.get(s);
			num1.add(value);
		}
		for(String s: player2.getList()){
			value = map.get(s);
			num2.add(value);
		}
		for(String s: player3.getList()){
			value = map.get(s);
			num3.add(value);
		}
		Collections.sort(num1);
		Collections.sort(num2);
		Collections.sort(num3);
		player1.getList().clear();
		player2.getList().clear();
		player3.getList().clear();
		for(int num: num1){
            player1.getList().add((String) map.keySet().toArray()[num]);
        }
        for(int num: num2){
            player2.getList().add((String) map.keySet().toArray()[num]);
        }
        for(int num: num3){
            player3.getList().add((String) map.keySet().toArray()[num]);
        }
		System.out.println(player1.getName()+":"+player1.getList());
		System.out.println(player2.getName()+":"+player2.getList());
		System.out.println(player3.getName()+":"+player3.getList());
	}
	
}
	

